<template>
  <div class="pwd-container">
    <div class="pwd-container-main">
      <form action="#">
        <input type="text" class="phone-ipt" placeholder="请输入手机号" v-model="phoneNumber"><br>
        <input type="password" class="pwd-ipt" placeholder="请输入密码" v-model="password"><br>
        <div class="pwd-config">
          <span>密码登录</span>
          <div class="zidong-login">
            <input type="checkbox">
            <span>自动登录</span>
          </div>
        </div>
        <button class="pwd-btn" @click.prevent="pwdLogin">登录</button>
      </form>
    </div>
    <footer class="pwd-login-bottom">
      <a @click="goOtherLogin" href="javascript:;" class="go-other-login">&lt;&nbsp;其他登录方式</a>
      <a href="javascript:;" class="txt-r">&lt;&nbsp;没用账号？免费注册</a>
    </footer>
  </div>
</template>

<script>
import { PwdLoginApi } from '@/requset/api'
export default {
  data() {
    return {
      password: '5201314',
      phoneNumber: '18791706142',
      userInfo: {}
    }
  },
  methods: {
    goOtherLogin() {
      this.$store.commit('goOtherLogin')
    },
    // 密码登录
    pwdLogin() {
      // 调用 密码登录接口
      PwdLoginApi({ phone: this.phoneNumber, password: this.password }).then(({ data: res }) => {
        // 将用户信息存放在 vuex 中
        this.$store.commit('UserInfo', res)
        // 设置 cookie
        this.$cookie.set('pwdcookie', res.cookie)
        // 更新 Header 组件
        this.$store.commit('UpdateKey')
        // 关闭登录模态框 正式登录成功
        this.$store.commit('ToggleLogin')
      })
    }
  }
}
</script>

<style lang="less" scoped>
@import '../../assets/base.less';
.pwd-container {
  align-content: space-between;
  height: 315px;
  padding-top: 10px;
}
.pwd-container-main {
  width: 100%;
  height: 200px;
  text-align: center;
  border-bottom: 1px solid #ccc;
  padding-bottom: 50px;
  form {
    display: inline-block;
    text-align: left;
    padding: 30px 0;
    input {
      height: 26px;
      outline: none;
      border: 1px solid #cdcdcd;
      border-radius: 3px;
      font-size: 12px;
      text-indent: 0.5em;
    }
    .phone-ipt {
      width: 200px;
      margin-bottom: 23px;
    }
    .pwd-ipt {
      width: 200px;
    }
    .pwd-config {
      display: flex;
      align-items: center;
      font-size: 12px;
      color: #666666;
      margin-top: 7px;
      justify-content: space-between;
      .zidong-login {
        display: flex;
        align-items: center;
      }
    }
    .pwd-btn {
      width: 100%;
      height: 30px;
      background-color: #3b8ad4;
      border: 1px solid #3984ce;
      border-radius: 5px;
      margin-top: 15px;
      color: #fff;
      cursor: pointer;
    }
  }
}
.pwd-login-bottom {
  font-size: 12px;
  padding: 0 20px;
  a {
    line-height: 50px;
    text-decoration: none;
  }
  .go-other-login {
    color: #0c72c3;
  }
  .txt-r {
    float: right;
    color: #9d9d9d;
  }
}
</style>